// net install desctable, from("https://tdmize.github.io/data/desctable")

cd " " // Set working directory eg: "/Users/xxx/yyy/code"
// Import data
use "data.dta", clear

// make output folder
mkdir "output"


// Table 1 Panel (a)
encode gender, gen(gender_cat)
encode education, gen(education_cat)
encode court_level, gen(court_level_cat)

desctable  i.gender_cat age i.education_cat i.court_level_cat volume_of_cases_2023 years_of_work_experience familiarity_with_ai trust_in_ai, filename("output/Table1 - Panle(a).xlsx") dec(2)  stats(N mean sd)

// Table 1 Panel (b)
encode initial_decisions, gen(initial_decisions_cat)
encode final_decisions, gen(final_decisions_cat)

desctable  i.initial_decisions_cat i.final_decisions_cat sentence confidence_in_decisions approval_of_ai_reasoning, filename("output/Table1 - Panle(b).xlsx") dec(2)  stats(N mean sd)


// Figure 2 Panel (a)

//(1) vs. (3)
tabi 16 19 \ 19 18,exact

// (2) vs. (4)
tabi 16 21 \ 16 14,exact


// Figure 2 Panel (b)
ttest sentence if treat == 0, by(ai)  level(95)
ttest sentence if treat == 1, by(ai)  level(95)
ttest sentence if ai == 0, by(treat)  level(95)
ttest sentence if ai == 1, by(treat)  level(95)


// Interaction Effect
reg sentence treat ai treat#ai


//Effect on subgroups: Triple difference
global control_vars age i.gender_cat i.education_cat i.court_level_cat 

reg sentence i.treat##i.ai##(c.time_spent_on_experiment c.years_of_work_experience c.familiarity_with_ai c.trust_in_ai)
reg sentence i.treat##i.ai##(c.time_spent_on_experiment c.years_of_work_experience c.familiarity_with_ai c.trust_in_ai) $control_vars

